using System;
using UnityEngine;

public class ColorButton : MonoBehaviour
{
	private void Awake()
	{
		this.button.ButtonDownEvent += this.OnMsgButtonDown;
		this.button.ButtonUpEvent += this.OnMsgButtonUp;
		this.sprite = this.targetObject.GetComponent<tk2dSprite>();
		this.slicedSprite = this.targetObject.GetComponent<tk2dSlicedSprite>();
		this.textMesh = this.targetObject.GetComponent<tk2dTextMesh>();
		this.planeRound = this.targetObject.GetComponent<PlaneRoundSpotObject>();
		this.planeMesh = this.targetObject.GetComponent<PlaneMeshObject>();
		if (this.randomColor)
		{
			int num = UnityEngine.Random.Range(0, ColorButton.colors.Length);
			this.downColor = ColorButton.colors[num];
		}
	}

	private void Start()
	{
		this.SetOriginalColor();
	}

	public void SetOriginalColor()
	{
		if (null != this.sprite)
		{
			this.originalColor = this.sprite.color;
		}
		if (null != this.slicedSprite)
		{
			this.originalColor = this.slicedSprite.color;
		}
		if (null != this.textMesh)
		{
			this.originalColor = this.textMesh.color;
		}
		if (null != this.planeRound)
		{
			this.originalColor = this.planeRound.color;
		}
		if (null != this.planeMesh)
		{
			this.originalColor = this.planeMesh.color;
		}
	}

	private void OnMsgButtonDown(tk2dButton button)
	{
		if (this.randomColor)
		{
			int num = UnityEngine.Random.Range(0, ColorButton.colors.Length);
			this.downColor = ColorButton.colors[num];
		}
		this.ChangeColor(this.downColor);
	}

	private void OnMsgButtonUp(tk2dButton button)
	{
		if (this.upColorOriginal)
		{
			this.ChangeColor(this.originalColor);
		}
		else
		{
			this.ChangeColor(this.upColor);
		}
	}

	private void ChangeColor(Color tempColor)
	{
		if (null != this.sprite)
		{
			this.sprite.color = tempColor;
		}
		if (null != this.slicedSprite)
		{
			this.slicedSprite.color = tempColor;
		}
		if (null != this.textMesh)
		{
			this.textMesh.color = tempColor;
			this.textMesh.Commit();
		}
		if (null != this.planeRound)
		{
			this.planeRound.color = tempColor;
		}
		if (null != this.planeMesh)
		{
			this.planeMesh.color = tempColor;
		}
	}

	private static Color[] colors = new Color[]
	{
		Color.red,
		Color.green,
		Color.blue,
		Color.cyan,
		Color.magenta,
		Color.yellow
	};

	public tk2dButton button;

	public GameObject targetObject;

	public bool upColorOriginal;

	public Color downColor = Color.white;

	public Color upColor = Color.white;

	public Color originalColor = Color.white;

	private tk2dSprite sprite;

	private tk2dSlicedSprite slicedSprite;

	private tk2dTextMesh textMesh;

	private PlaneRoundSpotObject planeRound;

	private PlaneMeshObject planeMesh;

	public bool randomColor;
}
